SET
YearwoX/2000*2100/
ModelN
Region
Scenario
Unit
Variable3/"Emi_CO2","Price_Carbon",CumCO2,Price_Carbon_2100,Average_Price_Carbon,Emi_TOT_AFOLU,Emi_Pos_AFOLU,Emi_Neg_AFOLU,Land_Pos_Change,Land_Neg_Change,Emi_TOT_AFOLU_NoBECCS/
Variable2/
$include ../define/allvariable.txt
Land_Cover_Pasture_Change_2010
Land_Cover_Other_Land_Change_2010
Land_Cover_Forest_Natural_Change_2010
Land_Cover_Forest_Managed_Change_2010
Land_Cover_Forest_Afforestation_and_Reforestation_Change_2010
Land_Cover_Forest_Change_2010
Land_Cover_Cropland_Energy_Crops_Change_2010
Land_Cover_Cropland_Change_2010
Land_Cover_Cropland_NonEnergy_Crops_Change_2010
Emi_CH4_AFOLU_RelativeBaU
Emi_CO2_AFOLU_RelativeBaU
Emi_N2O_AFOLU_RelativeBaU
Emi_CH4_N2O_AFOLU_RelativeBaU
Water_Consumption_Irrigation
Water_Withdrawal_Irrigatio
Emi_TOT_AFOLU
Emi_Pos_AFOLU
Emi_Neg_AFOLU
Land_Pos_Change
Land_Neg_Change
Emi_TOT_AFOLU_NoBECCS
/
Year
VarNetLandChange(Variable2)/
Land_Cover_Pasture_Change_2010
Land_Cover_Forest_Change_2010
Land_Cover_Cropland_Energy_Crops_Change_2010
Land_Cover_Cropland_NonEnergy_Crops_Change_2010
/
;
ALIAS(Variable2,Variable22);

PARAMETER
IPCCSR15All(ModelN,Scenario,Region,Variable2,Unit,Year,*)                              All variable
IPCCSR15AllPlus(ModelN,Scenario,Region,Variable2,Unit,YearwoX)                              All variable
;

$gdxin "../output/WorldCO2all.gdx"
$load ModelN,Scenario,Unit,Year
$gdxin "../output/IPCCSR15All.gdx"
$load Region,IPCCSR15All

SET
RegionWorld(Region)/World/
CO2Emi/0*10000/
Year5(Year)/X2015,X2025,X2035,X2045,X2055,X2065,X2075,X2085,X2095/
Year10(Year)/X2010,X2020,X2030,X2040,X2050,X2060,X2070,X2080,X2090,X2100/
StartendY(Year)/X2010,X2100/
StartY(Year)/X2010/
Year5map(Year,Year,Year)/
X2015   .       X2010   .       X2020
X2025   .       X2020   .       X2030
X2035   .       X2030   .       X2040
X2045   .       X2040   .       X2050
X2055   .       X2050   .       X2060
X2065   .       X2060   .       X2070
X2075   .       X2070   .       X2080
X2085   .       X2080   .       X2090
X2095   .       X2090   .       X2100
/
SSP/SSP1*SSP5/
RCP/19,26,34,45,60/
$ontext
Scenariomap(Scenario,SSP,RCP)/
SSP1-19        .        SSP1        .        19
SSP1-26        .        SSP1        .        26
SSP1-34        .        SSP1        .        34
SSP1-45        .        SSP1        .        45
SSP2-19        .        SSP2        .        19
SSP2-26        .        SSP2        .        26
SSP2-34        .        SSP2        .        34
SSP2-45        .        SSP2        .        45
SSP2-60        .        SSP2        .        60
SSP3-34        .        SSP3        .        34
SSP3-45        .        SSP3        .        45
SSP3-60        .        SSP3        .        60
*SSP4-19        .        SSP4        .        19
SSP4-26        .        SSP4        .        26
SSP4-34        .        SSP4        .        34
SSP4-45        .        SSP4        .        45
SSP4-60        .        SSP4        .        60
SSP5-19        .        SSP5        .        19
SSP5-26        .        SSP5        .        26
SSP5-34        .        SSP5        .        34
SSP5-45        .        SSP5        .        45
SSP5-60        .        SSP5        .        60
/
$offtext
StartendYTCRE(ModelN,Scenario,Region,Variable3,Unit,Year)
MapYear2(Year,YearwoX)/
X2000        .        2000
X2001        .        2001
X2002        .        2002
X2003        .        2003
X2004        .        2004
X2005        .        2005
X2006        .        2006
X2007        .        2007
X2008        .        2008
X2009        .        2009
X2010        .        2010
X2011        .        2011
X2012        .        2012
X2013        .        2013
X2014        .        2014
X2015        .        2015
X2020        .        2020
X2025        .        2025
X2030        .        2030
X2035        .        2035
X2040        .        2040
X2045        .        2045
X2050        .        2050
X2055        .        2055
X2060        .        2060
X2065        .        2065
X2070        .        2070
X2075        .        2075
X2080        .        2080
X2085        .        2085
X2090        .        2090
X2095        .        2095
X2100        .        2100
/
MapVland(Variable2,Variable2)/
"Land_Cover_Pasture"    .       "Land_Cover_Pasture_Change_2010"
"Land_Cover_Other_Land" .       "Land_Cover_Other_Land_Change_2010"
"Land_Cover_Forest_Natural_Forest"      .       "Land_Cover_Forest_Natural_Change_2010"
"Land_Cover_Forest_Managed"     .       "Land_Cover_Forest_Managed_Change_2010"
"Land_Cover_Forest_Afforestation_and_Reforestation"     .       "Land_Cover_Forest_Afforestation_and_Reforestation_Change_2010"
"Land_Cover_Forest"     .       "Land_Cover_Forest_Change_2010"
"Land_Cover_Cropland_Energy_Crops"      .       "Land_Cover_Cropland_Energy_Crops_Change_2010"
"Land_Cover_Cropland"   .       "Land_Cover_Cropland_Change_2010"
"Land_Cover_Cropland_NonEnergy_Crops"      .       "Land_Cover_Cropland_NonEnergy_Crops_Change_2010"
/
MapVRelBaU(Variable2,Variable2)/
Emi_CH4_AFOLU_RelativeBaU	.	Emi_CH4_AFOLU
Emi_CO2_AFOLU_RelativeBaU	.	Emi_CO2_AFOLU
Emi_N2O_AFOLU_RelativeBaU	.	Emi_N2O_AFOLU
Emi_CH4_N2O_AFOLU_RelativeBaU	.	Emi_CH4_N2O_AFOLU
/

;
Alias(Year,Year1,Year2), (Variable2,Variable20)

PARAMETER
CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,*)                              CO2 emissions
CumCO2Emis(ModelN,Scenario,Region,Variable3,Unit)                                  Cumulative CO2 emissions
NetZeroTimingCO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year)
NetZeroTimingCO2Emis2(ModelN,Scenario,Region,Variable3,Unit,Year)                  Timing of net zero emissions
TCRECumCO2Emis(ModelN,Scenario,Region,Variable3,Unit)                              TCRE cumulative CO2 emissions
CarbonPrice_load(ModelN,Scenario,Region,Variable3,Unit,Year,*)
CarbonPrice_NPV(ModelN,Scenario,Region,Variable3,Unit)
CarbonPrice_NPV_SSP(ModelN,SSP,RCP,Region,Variable3,Unit)
CarbonPrice_NPV_SSP_rel(ModelN,SSP,RCP,Region,Variable3,Unit)
Discount(Year10)
CarbonPrice_NPV_cat(ModelN,Scenario,Region,Variable3,CO2Emi,Unit)
CarbonPrice_NPV_stat(Region,*,CO2Emi,Unit)
Deg2CO2Emis(ModelN,Scenario,Unit,Year)                    2 degree category scenarios
PeakWarming(ModelN,Scenario)                              Peak warming
PeakWarmingF(ModelN,Scenario,*)                              Peak warming flag
Warming2100F(ModelN,Scenario,*)                              Peak warming flag

NetZeroTimingAFOLUEmis(ModelN,Scenario,Region,Variable3,Unit,Year)
NetZeroTimingAFOLUEmis2(ModelN,Scenario,Region,Variable3,Unit,Year)                  Timing of AFOLU's net zero emissions

AFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit,Year,*)                              CO2 emissions
CumAFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit)                                  Cumulative CO2 emissions
;

$gdxin "../output/WorldCO2all.gdx"
$load CO2Emis=IPCCSR15WorldCO2Emi
$gdxin "../output/CarbonPrice.gdx"
$load CarbonPrice_load=IPCCSR15WorldCarPrice

IPCCSR15All(ModelN,Scenario,Region,"Emi_TOT_AFOLU","Mt CO2/yr",Year,"Value")$(SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year1,"Value")) AND SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_AFOLU",Unit,Year1,"Value")) AND SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_N2O_AFOLU",Unit,Year1,"Value")) AND SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Carbon_Sequestration_CCS_Biomass",Unit,Year1,"Value")))
=SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year,"Value"))+25*SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_AFOLU",Unit,Year,"Value"))+298*SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_N2O_AFOLU",Unit,Year,"Value"))/1000+SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Carbon_Sequestration_CCS_Biomass",Unit,Year,"Value"))*(-1);

IPCCSR15All(ModelN,Scenario,Region,"Emi_TOT_AFOLU_NoBECCS","Mt CO2/yr",Year,"Value")$(SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year1,"Value")) AND SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_AFOLU",Unit,Year1,"Value")) AND SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_N2O_AFOLU",Unit,Year1,"Value")))
=SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year,"Value"))+25*SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_AFOLU",Unit,Year,"Value"))+298*SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_N2O_AFOLU",Unit,Year,"Value"))/1000;

IPCCSR15All(ModelN,Scenario,Region,"Emi_Pos_AFOLU","Mt CO2/yr",Year,"Value")$(SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year1,"Value")) AND SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_AFOLU",Unit,Year1,"Value")) AND SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_N2O_AFOLU",Unit,Year1,"Value")))
=SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year,"Value"))$(SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year,"Value"))>0)
+25*SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_AFOLU",Unit,Year,"Value"))
+298*SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_N2O_AFOLU",Unit,Year,"Value"))/1000;

IPCCSR15All(ModelN,Scenario,Region,"Emi_Neg_AFOLU","Mt CO2/yr",Year,"Value")$(SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year1,"Value")) AND SUM((Unit,Year1),IPCCSR15All(ModelN,Scenario,Region,"Carbon_Sequestration_CCS_Biomass",Unit,Year1,"Value")))
=SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year,"Value"))$(SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CO2_AFOLU",Unit,Year,"Value"))<0)
+SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Carbon_Sequestration_CCS_Biomass",Unit,Year,"Value"))*(-1);

AFOLUTOTEmis(ModelN,Scenario,Region,"Emi_TOT_AFOLU","Mt CO2/yr",Year,"Value")=IPCCSR15All(ModelN,Scenario,Region,"Emi_TOT_AFOLU","Mt CO2/yr",Year,"Value");

NetZeroTimingAFOLUEmis(ModelN,Scenario,Region,Variable3,Unit,Year)$(AFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value") AND AFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value")<=0)=1;
NetZeroTimingAFOLUEmis(ModelN,Scenario,Region,Variable3,Unit,Year)$(SMIN(Year1$(NetZeroTimingAFOLUEmis(ModelN,Scenario,Region,Variable3,Unit,Year1)),ORD(Year1))<ORD(Year))=0;
NetZeroTimingAFOLUEmis2(ModelN,Scenario,Region,Variable3,Unit,Year)$(ORD(Year)<=SUM(Year1$(NetZeroTimingAFOLUEmis(ModelN,Scenario,Region,Variable3,Unit,Year1)),ORD(Year1)))=1;
NetZeroTimingAFOLUEmis2(ModelN,Scenario,Region,Variable3,Unit,Year)$(AFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value") AND SUM(Year1$(AFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit,Year1,"Value")<0),1)=0)=1;
CumAFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit)=((SUM(Year$(Year5(Year) OR Year10(Year)),AFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value"))*2-SUM(Year$(StartendY(Year)),AFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value")))*5/2
-AFOLUTOTEmis(ModelN,Scenario,Region,Variable3,Unit,"X2010","Value"))/1000;

*execute_unload '../output/temp.gdx'
*NetZeroTimingAFOLUEmis,NetZeroTimingAFOLUEmis2,
*CumAFOLUTOTEmis,AFOLUTOTEmis,IPCCSR15All
*;

CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value")$(NOT (CO2Emis(ModelN,Scenario,Region,Variable3,Unit,"X2010","Value") AND CO2Emis(ModelN,Scenario,Region,Variable3,Unit,"X2100","Value")))=0;

CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year5,"Value")$(CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year5,"Value")=0)=
        SUM((Year2,Year1)$(Year5map(Year5,Year1,Year2)),CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year1,"Value")+CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year2,"Value"))/2;
PeakWarming(ModelN,Scenario)$(SUM((Year,UNIT)$(IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,Year,"Value")>0),1))=SMAX((Year,UNIT)$(IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,Year,"Value")>0),IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,Year,"Value"));

PeakWarmingF(ModelN,Scenario,"1.5Deg")$(PeakWarming(ModelN,Scenario)<=1.6 AND PeakWarming(ModelN,Scenario))=1;
PeakWarmingF(ModelN,Scenario,"2Deg")$(PeakWarming(ModelN,Scenario)<=2 AND PeakWarming(ModelN,Scenario)>1.6)=1;
PeakWarmingF(ModelN,Scenario,"2.5Deg")$(PeakWarming(ModelN,Scenario)<=2.5 AND PeakWarming(ModelN,Scenario)>2)=1;
PeakWarmingF(ModelN,Scenario,"Over2.5Deg")$(PeakWarming(ModelN,Scenario)>2.5)=1;

Warming2100F(ModelN,Scenario,"1.5Deg")$(SUM(Unit,IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,"X2100","Value"))<=1.6 AND SUM(Unit,IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,"X2100","Value")))=1;
Warming2100F(ModelN,Scenario,"2Deg")$(SUM(Unit,IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,"X2100","Value"))<=2 AND SUM(Unit,IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,"X2100","Value"))>1.6)=1;
Warming2100F(ModelN,Scenario,"2.5Deg")$(SUM(Unit,IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,"X2100","Value"))<=2.5 AND SUM(Unit,IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,"X2100","Value"))>2)=1;
Warming2100F(ModelN,Scenario,"Over2.5Deg")$(SUM(Unit,IPCCSR15All(ModelN,Scenario,"World","Diagnostics_MAGICC6_Temperature_Global_Mean",Unit,"X2100","Value"))>2.5)=1;

NetZeroTimingCO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year)$(CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value") AND CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value")<=1000)=1;
NetZeroTimingCO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year)$(SMIN(Year1$(NetZeroTimingCO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year1)),ORD(Year1))<ORD(Year))=0;
NetZeroTimingCO2Emis2(ModelN,Scenario,Region,Variable3,Unit,Year)$(ORD(Year)<=SUM(Year1$(NetZeroTimingCO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year1)),ORD(Year1)))=1;
NetZeroTimingCO2Emis2(ModelN,Scenario,Region,Variable3,Unit,Year)$(CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value") AND SUM(Year1$(CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year1,"Value")<0),1)=0)=1;
CumCO2Emis(ModelN,Scenario,Region,Variable3,Unit)=((SUM(Year$(Year5(Year) OR Year10(Year)),CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value"))*2-SUM(Year$(StartendY(Year)),CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value")))*5/2
-CO2Emis(ModelN,Scenario,Region,Variable3,Unit,"X2010","Value"))/1000;

StartendYTCRE(ModelN,Scenario,Region,Variable3,Unit,"X2010")$(CumCO2Emis(ModelN,Scenario,Region,Variable3,Unit))=YES;
StartendYTCRE(ModelN,Scenario,Region,Variable3,Unit,Year)$(SMAX(Year1$(NetZeroTimingCO2Emis2(ModelN,Scenario,Region,Variable3,Unit,Year1)),ORD(Year1))=ORD(Year))=YES;
StartendYTCRE(ModelN,Scenario,Region,Variable3,Unit,"X2100")$(StartendYTCRE(ModelN,Scenario,Region,Variable3,Unit,"X2010") AND SUM(Year1$(StartendYTCRE(ModelN,Scenario,Region,Variable3,Unit,Year1)),1)=1)=YES;

TCRECumCO2Emis(ModelN,Scenario,Region,Variable3,Unit)=((SUM(Year$(NetZeroTimingCO2Emis2(ModelN,Scenario,Region,Variable3,Unit,Year) AND (Year5(Year) OR Year10(Year))),CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value"))*2-SUM(Year$(StartendYTCRE(ModelN,Scenario,Region,Variable3,Unit,Year)),CO2Emis(ModelN,Scenario,Region,Variable3,Unit,Year,"Value")))*5/2
-CO2Emis(ModelN,Scenario,Region,Variable3,Unit,"X2010","Value"))/1000;

Discount(Year10)=1.05**(10*(ORD(Year10)-1));
CarbonPrice_NPV(ModelN,Scenario,Region,Variable3,Unit)$(SUM(Year10$(CarbonPrice_load(ModelN,Scenario,Region,Variable3,Unit,Year10,"Value") AND Discount(Year10)),1))
=SUM(Year10$(Discount(Year10)),CarbonPrice_load(ModelN,Scenario,Region,Variable3,Unit,Year10,"Value")/Discount(Year10))/SUM(Year10$(CarbonPrice_load(ModelN,Scenario,Region,Variable3,Unit,Year10,"Value") AND Discount(Year10)),1);
CarbonPrice_NPV(ModelN,Scenario,Region,Variable3,Unit)$(TCRECumCO2Emis(ModelN,Scenario,Region,Variable3,Unit))=TCRECumCO2Emis(ModelN,Scenario,Region,Variable3,Unit);
CarbonPrice_NPV(ModelN,Scenario,Region,"CumCO2",Unit)=SUM(Variable3,CumCO2Emis(ModelN,Scenario,Region,Variable3,Unit));
CarbonPrice_NPV(ModelN,Scenario,Region,"Price_Carbon_2100",Unit)=CarbonPrice_load(ModelN,Scenario,Region,"Price_Carbon",Unit,"X2100","Value");


$batinclude Co2categorize.gms 500 550 600
$batinclude Co2categorize.gms 600 650 700
$batinclude Co2categorize.gms 700 750 800
$batinclude Co2categorize.gms 800 850 900
$batinclude Co2categorize.gms 900 950 1000
$batinclude Co2categorize.gms 1000 1100 1200
$batinclude Co2categorize.gms 1200 1300 1400
$batinclude Co2categorize.gms 1400 1500 1600
$batinclude Co2categorize.gms 1600 1700 1800
$batinclude Co2categorize.gms 1800 1900 2000
$batinclude Co2categorize.gms 2000 2100 2200
$batinclude Co2categorize.gms 2200 2300 2400
$batinclude Co2categorize.gms 2400 2500 2600
CarbonPrice_NPV_stat(Region,"MeanPrice",CO2Emi,Unit)$(SUM((ModelN,Scenario)$CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit),1))=SUM((ModelN,Scenario)$CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit),CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit))/SUM((ModelN,Scenario)$CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit),1);
CarbonPrice_NPV_stat(Region,"MaxPrice",CO2Emi,Unit)$(SUM((ModelN,Scenario)$CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit),1))=SMAX((ModelN,Scenario)$CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit),CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit));
CarbonPrice_NPV_stat(Region,"MinPrice",CO2Emi,Unit)$(SUM((ModelN,Scenario)$CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit),1))=SMIN((ModelN,Scenario)$CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit),CarbonPrice_NPV_cat(ModelN,Scenario,Region,"Price_carbon",CO2Emi,Unit));

$ontext
CarbonPrice_NPV_SSP(ModelN,SSP,RCP,Region,Variable3,Unit)=SUM(Scenario$(Scenariomap(Scenario,SSP,RCP)),CarbonPrice_NPV(ModelN,Scenario,Region,Variable3,Unit));
CarbonPrice_NPV_SSP_rel(ModelN,SSP,RCP,Region,Variable3,Unit)=CarbonPrice_NPV_SSP(ModelN,SSP,RCP,Region,Variable3,Unit);
CarbonPrice_NPV_SSP_rel(ModelN,SSP,RCP,Region,"Price_Carbon",Unit)$(CarbonPrice_NPV_SSP(ModelN,SSP,"45",Region,"Price_Carbon",Unit))=CarbonPrice_NPV_SSP(ModelN,SSP,RCP,Region,"Price_Carbon",Unit)/CarbonPrice_NPV_SSP(ModelN,SSP,"45",Region,"Price_Carbon",Unit);
$offtext

Deg2CO2Emis(ModelN,Scenario,Unit,Year)$(TCRECumCO2Emis(ModelN,Scenario,"World","Emi_CO2",Unit)>=1320 AND TCRECumCO2Emis(ModelN,Scenario,"World","Emi_CO2",Unit)<=2270)=
  CO2Emis(ModelN,Scenario,"World","Emi_CO2",Unit,Year,"Value");


execute_unload '../output/cumulativeEmissions.gdx' CumCO2Emis
NetZeroTimingCO2Emis,NetZeroTimingCO2Emis2
NetZeroTimingAFOLUEmis,NetZeroTimingAFOLUEmis2,CumAFOLUTOTEmis,AFOLUTOTEmis,
TCRECumCO2Emis
StartendYTCRE
CarbonPrice_NPV
Discount
CarbonPrice_load
CarbonPrice_NPV_SSP_rel
CarbonPrice_NPV_SSP
CarbonPrice_NPV_cat
CarbonPrice_NPV_stat
Deg2CO2Emis
;
*AIM Baseline issue
IPCCSR15All(ModelN,"EN_NoPolicy",Region,variable2,Unit,Year,"Value")=IPCCSR15All(ModelN,"EN_NPi2100",Region,variable2,Unit,Year,"Value");

IPCCSR15All(ModelN,Scenario,Region,"Land_Cover_Cropland_NonEnergy_Crops",Unit,Year,"Value")$(SUM(Year1,IPCCSR15All(ModelN,Scenario,Region,"Land_Cover_Cropland",Unit,Year1,"Value")) AND SUM(Year1,IPCCSR15All(ModelN,Scenario,Region,"Land_Cover_Cropland_Energy_Crops",Unit,Year1,"Value")))=IPCCSR15All(ModelN,Scenario,Region,"Land_Cover_Cropland",Unit,Year,"Value")-IPCCSR15All(ModelN,Scenario,Region,"Land_Cover_Cropland_Energy_Crops",Unit,Year,"Value");

IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_N2O_AFOLU","Mt CO2/yr",Year,"Value")$(SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_AFOLU",Unit,Year,"Value")) AND SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_N2O_AFOLU",Unit,Year,"Value")))
  =25*SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_CH4_AFOLU",Unit,Year,"Value"))+298*SUM(Unit,IPCCSR15All(ModelN,Scenario,Region,"Emi_N2O_AFOLU",Unit,Year,"Value"))/1000;

IPCCSR15All(ModelN,Scenario,Region,"Carbon_Sequestration_CCS_Biomass",Unit,Year,"Value")=IPCCSR15All(ModelN,Scenario,Region,"Carbon_Sequestration_CCS_Biomass",Unit,Year,"Value")*(-1);
IPCCSR15All(ModelN,Scenario,Region,"Carbon_Sequestration_Land_Use",Unit,Year,"Value")=IPCCSR15All(ModelN,Scenario,Region,"Carbon_Sequestration_Land_Use",Unit,Year,"Value")*(-1);

IPCCSR15All(ModelN,Scenario,Region,Variable2,"million ha",Year,"Value")$(SUM((Variable20)$(MapVland(Variable20,Variable2) AND IPCCSR15All(ModelN,Scenario,Region,Variable20,"million ha",Year,"Value")),1))=
  SUM(Variable20$MapVland(Variable20,Variable2),IPCCSR15All(ModelN,Scenario,Region,Variable20,"million ha",Year,"Value")-IPCCSR15All(ModelN,Scenario,Region,Variable20,"million ha","X2010","Value"));

IPCCSR15All(ModelN,Scenario,Region,Variable22,Unit,Year,"Value")$(SUM(Variable2$MapVRelBaU(Variable22,Variable2),1))=SUM(Variable2$(MapVRelBaU(Variable22,Variable2) AND IPCCSR15All(ModelN,"EN_NoPolicy",Region,Variable2,Unit,Year,"Value") AND IPCCSR15All(ModelN,Scenario,Region,Variable2,Unit,Year,"Value")),IPCCSR15All(ModelN,"EN_NoPolicy",Region,Variable2,Unit,Year,"Value")-IPCCSR15All(ModelN,Scenario,Region,Variable2,Unit,Year,"Value"));



IPCCSR15All(ModelN,Scenario,Region,"Land_Pos_Change","million ha",Year,"Value")=SUM(Variable2$(VarNetLandChange(Variable2) and IPCCSR15All(ModelN,Scenario,Region,Variable2,"million ha",Year,"Value")>0),IPCCSR15All(ModelN,Scenario,Region,Variable2,"million ha",Year,"Value"));
IPCCSR15All(ModelN,Scenario,Region,"Land_Neg_Change","million ha",Year,"Value")=SUM(Variable2$(VarNetLandChange(Variable2) and IPCCSR15All(ModelN,Scenario,Region,Variable2,"million ha",Year,"Value")<0),IPCCSR15All(ModelN,Scenario,Region,Variable2,"million ha",Year,"Value"));

*---- Compilation of all data
IPCCSR15AllPlus(ModelN,Scenario,Region,Variable2,Unit,YearwoX)=SUM(MapYear2(Year,YearwoX),IPCCSR15All(ModelN,Scenario,Region,Variable2,Unit,Year,"Value"));

*-----RoH include
SET
ScenarioRoH/
$include ../define/RiskHunger_Scenario.set
/
ScenariomapRoH(ScenarioRoH,ModelN,Scenario)/
$include ../define/RiskHunger_ScenarioMap.txt
/
dum1/DUM/
dum2/fao_based/
;

PARAMETER
RoH_load(dum1,dum2,ScenarioRoH,Region,YearwoX)
;

$gdxin "../data/AllModel_AR6.gdx"
$load RoH_load=Risk_Org

IPCCSR15AllPlus(ModelN,Scenario,Region,"Population_Risk_of_Hunger","million",YearwoX)$(NOT IPCCSR15AllPlus(ModelN,Scenario,Region,"Population_Risk_of_Hunger","million",YearwoX))=SUM(ScenarioRoH$ScenariomapRoH(ScenarioRoH,ModelN,Scenario),RoH_load("DUM","fao_based",ScenarioRoH,Region,YearwoX));





execute_unload '../output/IPCCSR15allPlus.gdx'
Region
IPCCSR15AllPlus
PeakWarming
PeakWarmingF
Warming2100F
RoH_load
;
